package com.tjetc.service.impl;

import com.tjetc.dao.AdoptMapper;
import com.tjetc.domain.Admin;
import com.tjetc.domain.Adopter;
import com.tjetc.service.AdoptService;
import com.tjetc.utils.Db;
import com.tjetc.vo.Result;

public class AdoptServiceImpl implements AdoptService {
    private AdoptMapper adoptMapper = Db.getMapper(AdoptMapper.class);

    @Override
    public Result login(String username, String password) {
        Adopter adopter = adoptMapper.getByUserNameAndPassword(username, password);
        if (adopter != null) {
            return new Result(200, "登陆成功", adopter);
        } else {
            return new Result(500, "登陆失败", null);
        }
    }

    @Override
    public Result register(Adopter adopter) {
        Adopter adopter1=adoptMapper.getByUserNameAndPassword(adopter.getUsername(),null);
        if (adopter1==null){
            int rows=adoptMapper.add(adopter);
            if (rows==1){
                return new Result(200,"添加成功",null);
            }
            else {
                return new Result(500,"添加失败",null);
            }
        }
        return new Result(500,"该用户名已存在",null);
    }
}
